package com.lee.dutylower.db.greenEntity;

import com.lee.dutylower.db.BaseDB;

import org.greenrobot.greendao.DaoException;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Property;
import org.greenrobot.greendao.annotation.ToMany;

import java.util.List;
import com.lee.dutylower.db.greendao.DaoSession;
import com.lee.dutylower.db.greendao.SoldierDao;
import com.lee.dutylower.db.greendao.SquadDao;

/**
 * Created by lijie on 2017/4/22.
 */

@Entity
public class Squad  extends BaseDB {
    @Id(autoincrement = true)
    private Long suqadId;
    @Property
    private String squadName;

    @ToMany(referencedJoinProperty = "squadID")
    private List<Soldier> soldiers;
    /** Used to resolve relations */
    @Generated(hash = 2040040024)
    private transient DaoSession daoSession;
    /** Used for active entity operations. */
    @Generated(hash = 365134275)
    private transient SquadDao myDao;

    @Generated(hash = 1698931428)
    public Squad(Long suqadId, String squadName) {
        this.suqadId = suqadId;
        this.squadName = squadName;
    }

    @Generated(hash = 1286534985)
    public Squad() {
    }

    public Long getSuqadId() {
        return this.suqadId;
    }

    public void setSuqadId(Long suqadId) {
        this.suqadId = suqadId;
    }

    public String getSquadName() {
        return this.squadName;
    }

    public void setSquadName(String squadName) {
        this.squadName = squadName;
    }

    /**
     * To-many relationship, resolved on first access (and after reset).
     * Changes to to-many relations are not persisted, make changes to the target entity.
     */
    @Generated(hash = 1947027259)
    public List<Soldier> getSoldiers() {
        if (soldiers == null) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            SoldierDao targetDao = daoSession.getSoldierDao();
            List<Soldier> soldiersNew = targetDao._querySquad_Soldiers(suqadId);
            synchronized (this) {
                if (soldiers == null) {
                    soldiers = soldiersNew;
                }
            }
        }
        return soldiers;
    }

    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    @Generated(hash = 1467588108)
    public synchronized void resetSoldiers() {
        soldiers = null;
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 128553479)
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.delete(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 1942392019)
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.refresh(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 713229351)
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.update(this);
    }

    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 115917130)
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getSquadDao() : null;
    }
}
